package edu.dayu.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

/**
 * @author by dayu
 * @date 2023/4/11.
 * 所有的 BeanPostProcessor 会在其他 bean 开始实例化之前完成实例化。
 */
@Component
@Slf4j
public class BeanPostProcessorTest implements BeanPostProcessor {
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        // springboot 默认集成了 logback，非常方便
        log.info("Bean '" + beanName + "' created : " + bean.toString());
        return bean;
    }
}
